﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>append & prepend</title>
    <style>
        .dynamic {
            color: red;
        }
    </style>
</head>
<body>
    <div>
        <select id="options">
            <option>append</option>
            <option>appendTo</option>
            <option>prepend</option>
            <option>prependTo</option>
        </select>
        <button id="button" onclick=" modifyElement() ">Modify</button>
    </div>
    <div style="height: 50px;"></div>
    <div id="main">
        <p>First Paragraph</p>
        <p>Second Paragraph</p>
        <p>Third Paragraph</p>
        <p>Fourth Paragraph</p>
    </div>
</body>
</html>
<script src="Scripts/jquery-2.1.4.js"></script>
<script language="javascript">
    function modifyElement() {
        var option = $("#options").val();
        //switch is JavaScript, not JQuery
        switch (option) {
            case "appendTo":
                $("<p class = 'dynamic'>this is appendTo</p>").appendTo("p");
                break;
            case "append":
                $("p").append("<p class = 'dynamic'>this is append</p>");
                break;
            case "prependTo":
                $("<p class = 'dynamic'>this is prependTo</p>").prependTo("p");
                break;
            case "prepend":
                $("p").prepend("<p class = 'dynamic'>this is prepend</p>");
                break;
        }
    }
</script>